package com.zkq.graduate.service.impl;

import com.zkq.graduate.mapper.UserAndRoleMapper;
import com.zkq.graduate.pojo.Role;
import com.zkq.graduate.pojo.Users;
import com.zkq.graduate.service.UserAndRoleService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author zhangkaiqiang
 * @Date 2019/12/1  13:58
 * @Description TODO
 */
@Service("userAndRoleService")
public class UserAndRoleServiceImpl implements UserAndRoleService {


	@Resource
	private UserAndRoleMapper userAndRoleMapper;
	/**
	 * 查找某个用户对应的所有角色
	 * @param users
	 * @return
	 */
	@Override
	public List<Role> findRoleByUser(Users users){
		List<Role> list=userAndRoleMapper.findRoleByUser(users);
		if(CollectionUtils.isEmpty(list)){
			return new ArrayList<>();
		}
		return list;
	}

	@Override
	public boolean batchInsert(List<Map<String, String>> userAndRole) {
		return !CollectionUtils.isEmpty(userAndRole) && userAndRoleMapper.batchInsert(userAndRole) == userAndRole.size();
	}


}
